package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  11:35 2020/7/17</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/7/17      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@RestController
@RequestMapping("/user")
@RefreshScope //开启刷新
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private String port;
    @Value("${personName}")
    private String personName;


    /**
    * @Date: 11:36 2020/7/17
    * @Param: [id]
    * @return: User
    * @NewDescription: 根据id查找用户
     *
     * 原来请求访问方式：
     * http://localhost:9091/user/findUserById?id=1
     *
     * restFul风格：
     * @RequestParam
     * @PathVariable("id")
     * @PathVariable
     * http://localhost:9091/user/findUserById/1
     *
     *
    **/
    @GetMapping("findUserById/{id}")
    public User findUserById(@PathVariable Integer id){
        /*try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        User user = userService.findUserById(id);
        user.setNote("生产者端口号是: " + port);
        return user;
    }
    /**
    * @Date: 10:33 2020/7/22
    * @Param: []
    * @return: java.lang.String
    * @NewDescription:  用于区分配置文件
    **/
    @GetMapping("/getPersonName")
    public String getPersonName(){
        return personName;
    }


}
